<?php


namespace App\mangodb;


use MongoDB\Client;
use think\facade\Log;

class chat
{
    private static $mangodb;

    private function __construct()
    {
        //连接MongoDB数据库
        self::$mangodb = new Client("mongodb://localhost:27017");
    }

    public function setDatabase($base)
    {
        //库名->集合名
        self::$mangodb->$base->$base;
    }

    public function add($data)
    {
        //添加一条数据
        $result = self::$mangodb->insertOne($data);
        if (!$result) Log::info('存储失败');
        return $result;
    }

    private function __clone(){}
}
